require 'net/telnet'
require 'pp'

module Amadeusdsl

# Connection module : offers a connection to the server 
  module Connection
    # Connection is a singleton object
    extend self

    # pass a command to the Adameus Server and return the results in a String array
    if Integer(RUBY_VERSION[2]) > 8 || (Integer(RUBY_VERSION[2]) == 8 && Integer(RUBY_VERSION[5]) == 7) #Ruby 1.9+ or 1.8.7
    
      def put(command)
          host = Net::Telnet.new('Host' => 'localhost', 'Port' => 12111)
         
          array = []
          line = host.cmd({"String"=>command.to_s,"flush"=>true})
          if (line != nil)
            line.each_line { |x| array << x.chomp}
          end
          host.close
          return array
      end  
    else #ruby < 1.8.7
        def put(command)
        host = Net::Telnet.new('Host' => 'localhost', 'Port' => 12111)
       
        array = []
        while line = host.gets
            array << line.chomp
        end
        host.flush 
        host.close
        return array
    end  
    end

  end
end

